package com.xlh.support.experimentshare.dao.helper;

import com.xlh.support.experimentshare.dao.ExperimentShareConfigMapper;
import com.xlh.support.experimentshare.domain.ExperimentShareConfig;
import com.xlh.support.experimentshare.domain.example.ExperimentShareConfigExample;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author cheer
 */
@Repository
public class ExperimentShareConfigMapperHelper {

    @Autowired
    private ExperimentShareConfigMapper experimentShareConfigMapper;

    public ExperimentShareConfig getByChapterId(Long chapterId) {
        ExperimentShareConfigExample example = new ExperimentShareConfigExample();
        example.or().andChapterIdEqualTo(chapterId)
                .andDeletedEqualTo(false);
        List<ExperimentShareConfig> shareConfigs = experimentShareConfigMapper.selectByExample(example);
        if (CollectionUtils.isNotEmpty(shareConfigs)) {
            return shareConfigs.get(0);
        }
        return null;
    }
}
